<?php
/**
 * Description: 获取事业单位试卷练习
 * User: lizengcai
 * Date: 16/12/4
 * Time: 10:00
 */

require __DIR__ . '/includes/utils.php';
class GetPaperExercise implements iController {
    /**
     * 缓存时间
     *
     */
    protected $_expires = 1800;

    /**
     * api请求处理主函数
     * @param array $queryArgs 就是$_REQUEST变量
     * @return array api返回结果，必须含response_code
     */
    public function output($queryArgs) {
        global $cmsdb;

        $allowedtype = array('institution');
        if (empty($queryArgs['paper_id']) || !in_array($queryArgs['paper_type'], $allowedtype))
            return genOutput(1000);

        switch($queryArgs['paper_type']) {
            case 'institution'; //事业单位
                $paperInfo = $cmsdb->getRow('SELECT * FROM `institution_papers` WHERE `id`=:paper_id',
                    array('paper_id' => $queryArgs['paper_id']));
                $questionsId = $cmsdb->getCol('SELECT question_id FROM `institution_relation_paper_question` WHERE  `paper_id`=:paper_id ORDER BY `number`',array('paper_id' => $queryArgs['paper_id']));
                if (empty($paperInfo))
                    return genOutput(1000);

                return genOutput(1, array(
                    'paper_id' => intval($queryArgs['paper_id']),
                    'paper_name' => $paperInfo->paper_name,
                    'questions' => InstitutionUtils::getQuestionsByInstitutionIds($questionsId),
                ));

            default:
                return genOutput(1000);
        }
    }
}